from django.db import models
from django.contrib import admin

class Province(models.Model):
    province = models.CharField(max_length=20)
    def __unicode__(self):
        return self.province
class ProvinceAdmin(admin.ModelAdmin):
    search_fields = ("province",)
admin.site.register(Province, ProvinceAdmin)

class City(models.Model):
    province = models.ForeignKey(Province)
    city = models.CharField(max_length=20)
    def __unicode__(self):
        return self.city
class CityAdmin(admin.ModelAdmin):
    pass
admin.site.register(City, CityAdmin)

class Zone(models.Model):
    city = models.ForeignKey(City)
    zone = models.CharField(max_length=20)
    def __unicode__(self):
        return self.zone
class ZoneAdmin(admin.ModelAdmin):
    pass
admin.site.register(Zone, ZoneAdmin)

class ZoneDetail(models.Model):
    zone = models.ForeignKey(Zone)
    zone_detail = models.CharField(max_length=20)
    def __unicode__(self):
        return self.zone_detail
class ZoneDetailAdmin(admin.ModelAdmin):
    pass
admin.site.register(ZoneDetail, ZoneDetailAdmin)

class Address(models.Model):
    zone_detail = models.ForeignKey(ZoneDetail)
    more = models.CharField(max_length=100)
    def __unicode__(self):
        return self.more
    def get_full_address(self):
        zone_detail = self.zone_detail
        zone = zone_detail.zone
        city = zone.city
        province = city.province
        return "%s %s %s %s %s"%(
                                 province.province
                                 ,zone.city.city
                                 ,zone.zone
                                 ,zone_detail.zone_detail
                                 ,self.more)
class AddressAdmin(admin.ModelAdmin):
    pass
admin.site.register(Address, AddressAdmin)


    
    